import fs from 'node:fs'

import download from 'download-git-repo'  // 下载模板
import ora from 'ora'

export function checkPath(filePath) {
    if(fs.existsSync(filePath)) {
        console.log('文件已存在')
        return true
    } else {
        return false
    }
}

export const downloadTemplate = (/*url,*/ branch, projectName) => {  // 地址可以写死
    return new Promise((resolve, reject) => {
        const spinner = ora(`正在下载模板...`)
        spinner.start()
        download(/*url,*/`direct:https://gitee.com/chinafaker/vue-template.git#${branch}`, projectName, { clone: true }, (err) => {
            if(err) {
                reject(err)
            } else {
                resolve()
                spinner.succeed(`下载模板成功`)
            }
        })
        
    })
}